const Router = require("koa-router")
const Server = require('./server')
const Check = require('./check')
const { auth } = require('@/lib/auth')

/**
 * 路由对象
 * @type {Router}
 */
const router = new Router({
	prefix: '/server'
})

/**
 * 图片上传
 */
router.post('/image-up', async function (ctx, next) {
  const path = Server.upImage(ctx)
  ctx.sendSuccess(path)
})

/**
 * 获取本地文件列表
 */
router.get("/fill-all", auth, async (ctx, next) =>{
  const data = await Server.fillAll(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除本地文件
 */
router.delete("/fill-remove", auth, async (ctx, next) =>{
  Check.fillRemove(ctx)
  await Server.fillRemove(ctx)
  ctx.sendSuccess('')
})

/**
 * 删除所有本地文件
 */
router.delete("/fill-remove-all", auth, async (ctx, next) =>{
  await Server.fillRemoveAll(ctx)
  ctx.sendSuccess('')
})

module.exports = router
